package com.config.appliation;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Queue;

/**
 *组件类
 */
@Component
public class JmsComponent {
    @Autowired
    JmsMessagingTemplate jmsMessagingTemplate;
    @Autowired
    Queue queue;

    /***
     * 发送消息
     * @param message
     */
    public void send(Message message) {
        jmsMessagingTemplate.convertAndSend(this.queue, message);
    }

    
    /***
     * 接收消息  使用@JmsListener注解
     * @param msg
     */
    @JmsListener(destination = "hello.javaboy")
    public void receive(Message msg) {
        System.out.println(msg);
    }
    
    /***
     * 创建一个queue对象
     * @return
     */
    @Bean
    Queue queue() {
        return new ActiveMQQueue("hello.javaboy");
    }
}
